﻿using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Limestone.MVC
{
    public static class HtmlHelpers
    {
        public static IHtmlString DisplayField(this HtmlHelper html, IField field)
        {
            return new HtmlString((field == null) ? "" : field.GetHtml());
        }

        public static IHtmlString LimeMap(this HtmlHelper html, IEnumerable<ILimeMapNode> nodes)
        {
            string htmlOutput = string.Empty;

            if (nodes.Any())
            {
                htmlOutput += "<ul>";
                foreach (var node in nodes)
                {
                    var css = (node.PageStub.Hidden) ? "page hidden" : "page";
                    htmlOutput += "<li class=\"node\" data-path=\""+node.PageStub.Path+"\">" + 
                                "<div class=\"" + css + "\">" +
                                "<div class=\"path\">" + node.PageStub.Path + "</div>" +
                                node.PageStub.Title +
                                "<div class=\"btn-group operate\">" +
                                "  <a class=\"btn dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><span class=\"caret\"></span></a>" +
                                "  <ul class=\"dropdown-menu\">" +
                                "    <li><a href=\"#\"><i class=\"icon-play\"></i> View</a></li>" +
                                "    <li><a href=\"#\"><i class=\"icon-pencil\"></i> Edit</a></li>" +
                                "    <li><a href=\"#\"><i class=\"icon-trash\"></i> Delete</a></li>" +
                                "    <li><a href=\"#\"><i class=\"icon-eye-close\"></i> Hide</a></li>" +
                                "  </ul>" +
                                "</div>" +
                                "<a class=\"btn btn-large add\" href=\"#\"><i class=\"icon-plus\"></i></a>" +
                                "</div>" +
                                html.LimeMap(node.Nodes) +
                                "</li>";
                }
                htmlOutput += "</ul>";
            }

            return new MvcHtmlString(htmlOutput);
        }
    }
}
